package com.longcai.controller.property;


import com.alibaba.fastjson.JSONObject;
import com.longcai.bean.ApiResult;
import com.longcai.entity.customer.ClyjUser;
import com.longcai.entity.property.ClyjUserPropertyRecord;
import com.longcai.service.property.ClyjUserPropertyRecordService;
import com.longcai.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 用户资产收益记录表 前端控制器
 * </p>
 *
 * @author M
 * @since 2019-04-29
 */
@Controller
@RequestMapping("/clyjUserPropertyRecord")
public class ClyjUserPropertyRecordController {
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private ClyjUserPropertyRecordService clyjUserPropertyRecordService;

    /**
     * 用户余额明细
     *
     * @param params
     * @return
     */
    @RequestMapping("/getAccount")
    @ResponseBody
    public ApiResult getAccount(@RequestBody JSONObject params) {

        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        return this.clyjUserPropertyRecordService.getAccount(clyjUser.getUserId());
    }

    /**
     * 筛选
     *
     * @param params
     * @return
     */
    @RequestMapping("/selectAccount")
    @ResponseBody
    public ApiResult selectAccount(@RequestBody JSONObject params) {
        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        return this.clyjUserPropertyRecordService.selectAccount(params, clyjUser.getUserId());
    }

    /**
     * 时间筛选
     *
     * @param params
     * @return
     */
    @RequestMapping("/select")
    @ResponseBody
    public ApiResult select(@RequestBody JSONObject params) {
        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        return this.clyjUserPropertyRecordService.select(params, clyjUser.getUserId());
    }

    /**
     * 零钱红包积分筛选
     *
     * @param params
     * @return
     */
    @RequestMapping("/selectall")
    @ResponseBody
    public ApiResult selectall(@RequestBody JSONObject params) {
        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        return this.clyjUserPropertyRecordService.selectall(params, clyjUser.getUserId());
    }


    /**
     * 积分红包零钱明细
     *
     * @param params
     * @return
     */
    @RequestMapping("/getAccountall")
    @ResponseBody
    public ApiResult getAccountall(@RequestBody JSONObject params) {

        String token = params.getString("token");
        if (token == null || "".equals(token)) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        ClyjUser clyjUser = tokenUtils.Itoken(token);
        if (clyjUser == null) {
            return ApiResult.fail("您好，你的账号已登陆失效，请重新登陆！");
        }
        //资产类型(0 零钱 1红包 2积分,3余额)
        String asset = params.getString("asset");
        return this.clyjUserPropertyRecordService.getAccountall(clyjUser.getUserId(),asset);
    }
}

